package com.lehecai.core.api.event;

import com.lehecai.core.YesNoStatus;
import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.lottery.LotteryType;
import com.lehecai.core.util.CoreDateUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

/**
 * Created by He Wang on 2015/1/22.
 */
public class SendConfig extends AbstractApiResultBean {


	public static final String QUERY_ID = "id";
	public static final String QUERY_LOTTERY_TYPE = "lottery_type";
	public static final String QUERY_PROP_ID = "prop_id";
	public static final String QUERY_IS_OPEN = "is_open";

	public static final String SET_LOTTERY_TYPE = "lottery_type";
	public static final String SET_PROP_ID = "prop_id";
	public static final String SET_IS_OPEN = "is_open";
	public static final String SET_EXP_TIME = "exp_time";
	public static final String SET_LIMIT_TIMES = "limit_times";
	public static final String SET_LARGEST_TIMES = "large_times";
	public static final String SET_DEADLINE = "deadline";

	private Long id;
	private LotteryType lotteryType;
	private YesNoStatus isOpen;
	private String expTime;
	private String limitTimes;
	private Long propId;
	private Date createdTime;
	private Date deadline;
	private Integer largestTimes;
	private Integer sentNums;
	private Integer usedNums;

	public static SendConfig convertFromJSONObject(JSONObject object) {
		if (object == null) {
			return null;
		}
		SendConfig sendConfig = new SendConfig();
		sendConfig.id = getLong(object, "id");
		sendConfig.lotteryType = LotteryType.getItem(getInt(object, "lottery_type"));
		sendConfig.isOpen = YesNoStatus.getItem(getInt(object, "is_open"));
		sendConfig.expTime = getString(object, "exp_time");
		sendConfig.limitTimes = getString(object, "limit_times");
		sendConfig.propId = getLong(object, "prop_id");
		sendConfig.createdTime = CoreDateUtils.parseDate(getString(object, "create_at"), CoreDateUtils.DATETIME);
		sendConfig.largestTimes = getInt(object, "large_times");
		sendConfig.deadline = CoreDateUtils.parseDate(getString(object, "deadline"), CoreDateUtils.DATETIME);
		sendConfig.sentNums = getInt(object, "send_nums");
		sendConfig.usedNums = getInt(object, "used_nums");
		return sendConfig;
	}

	public static List<SendConfig> convertFromJSONArray(JSONArray array) {
		if (array == null) {
			return null;
		}
		List<SendConfig> list = new ArrayList<SendConfig>();
		for (Iterator<?> iterator = array.iterator(); iterator.hasNext();) {
			JSONObject object = (JSONObject) iterator.next();
			list.add(convertFromJSONObject(object));
		}
		return list;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public LotteryType getLotteryType() {
		return lotteryType;
	}

	public void setLotteryType(LotteryType lotteryType) {
		this.lotteryType = lotteryType;
	}

	public YesNoStatus getIsOpen() {
		return isOpen;
	}

	public void setIsOpen(YesNoStatus isOpen) {
		this.isOpen = isOpen;
	}

	public String getExpTime() {
		return expTime;
	}

	public void setExpTime(String expTime) {
		this.expTime = expTime;
	}

	public String getLimitTimes() {
		return limitTimes;
	}

	public void setLimitTimes(String limitTimes) {
		this.limitTimes = limitTimes;
	}

	public Long getPropId() {
		return propId;
	}

	public void setPropId(Long propId) {
		this.propId = propId;
	}

	public Date getCreatedTime() {
		return createdTime;
	}

	public void setCreatedTime(Date createdTime) {
		this.createdTime = createdTime;
	}

	public Date getDeadline() {
		return deadline;
	}

	public void setDeadline(Date deadline) {
		this.deadline = deadline;
	}

	public Integer getLargestTimes() {
		return largestTimes;
	}

	public void setLargestTimes(Integer largestTimes) {
		this.largestTimes = largestTimes;
	}

	public Integer getSentNums() {
		return sentNums;
	}

	public void setSentNums(Integer sentNums) {
		this.sentNums = sentNums;
	}

	public Integer getUsedNums() {
		return usedNums;
	}

	public void setUsedNums(Integer usedNums) {
		this.usedNums = usedNums;
	}
}
